<%-- 
    Document   : listPatient
    Created on : Dec 5, 2014, 8:21:04 PM
    Author     : smile
--%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="entity.Student"%>
<%@page import="dao.StudentDAO"%>

<jsp:include page="../header.jsp"></jsp:include>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    List<Student> studentList = new ArrayList<Student>();
    String keyword = request.getParameter("keyword");
    String SearchType = request.getParameter("searchType");
    String SearchBtn = request.getParameter("searchBtn");
    if (SearchBtn != null) {
        studentList = StudentDAO.getStudentList(keyword, SearchType);
    } else {
        studentList = StudentDAO.getStudentList(null, null);
    }
%>
<script>
    $(document).ready(function() {
        $('#example').dataTable();
    });
</script>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>List of All Student</title>
    </head>
    <body>
        <div class="container">
            <h2>Student List</h2>
            <hr>
            <br>
            <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Student ID</th>
                        <th>Student Name</th>
                        <th>Batch</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tr>
                    <%
                        int i = 1;
                        for (Student st : studentList) {
                    %>
                    <td><%=i++%></td>

                    <td><%=st.getStudentID()%></td>
                    <td><%=st.getName()%></td>
                    <td><%=st.getBatch()%></td>
                    <td>
                        <a href="./editStudent.jsp?id=<%=st.getStudentID()%>">Edit </a> |
                        <a data-href="./deleteStudent.jsp?roll=<%=st.getStudentID()%>" data-toggle="modal" 
                           data-target="#confirm-delete"  href="#">Delete</a>
                    </td>
                </tr>
                <% }%>
            </table>
            <form action="addStudent.jsp" method="POST" style="display: inline">
                <input type="submit" name="addNewBtn" class="btn btn-primary" value="Add new Student" style="float: left" />
            </form>
        </div>

        <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">

                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Confirm</h4>
                    </div>

                    <div class="modal-body">
                        <p>Are you sure want to delete this Student?</p>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                        <a href="#" class="btn btn-danger danger">Delete</a>
                    </div>
                </div>
            </div>
        </div>



        <script>
            $('#confirm-delete').on('show.bs.modal', function(e) {
                $(this).find('.danger').attr('href', $(e.relatedTarget).data('href'));
            })
        </script>
    </body>
</html>
<jsp:include page="../footer.jsp"></jsp:include>
